package com.ecoolex.discount.sales.admin.graphql;

import com.ecoolex.discount.sales.admin.core.AdminConstant;
import com.ecoolex.framework.modularize.api.auth.annotation.AdminAuthoritativeRegister;
import com.ecoolex.framework.modularize.api.service.config.SystemConfig;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module;
import com.ecoolex.framework.web.api.graphql2.annotation.MutationField;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;

@GraphQL2Module(type = GraphQL2Module.Type.Admin,description = "其他")
public class OtherGraphql {

    @Autowired
    private SystemConfig systemConfig;

    @MutationField(field = "editHomePageSearchKeywordsConfig", description = "编辑首页搜索关键字配置")
    @AdminAuthoritativeRegister(parentKey = AdminConstant.AUTH_PROJECT_KEY, key = "DISCOUNT-SALES-ADMIN-HOME-PAGE-SEARCH-KEYWORDS-EDIT", name = "编辑首页搜索关键字配置")
    public boolean editHomePageSearchKeywords(@NonNull String keywords) {
        systemConfig.set(AdminConstant.CONFIG_HOME_PAGE_SEARCH_KEYWORDS, keywords, this.getClass().getSimpleName());
        return true;
    }
    
    @MutationField(field = "editYouWorldGiftCardBuyLimitConfig", description = "编辑由我礼品卡新用户购买限额配置")
    @AdminAuthoritativeRegister(parentKey = AdminConstant.AUTH_PROJECT_KEY, key = "DISCOUNT-SALES-ADMIN-YOU-WORLD-BUY-LIMIT-EDIT", name = "编辑由我礼品卡新用户购买限额配置")
    public boolean editYouWorldGiftCardBuyLimit(@NonNull BigDecimal value) {
        systemConfig.set(AdminConstant.CONFIG_YOU_WORLD_BUY_LIMIT, String.valueOf(value), this.getClass().getSimpleName());
        return true;
    }
}
